home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Griffith 0.9.8 / griffith-0.9.8-win32.exe / {app} / lib / initialize.py < prev    next >
Text File  |  2008-11-17  |  37KB  |  949 lines

  1. # -*- coding: UTF-8 -*-
  2.  
  3. __revision__ = '$Id: initialize.py 1038 2008-11-15 20:16:06Z mikej06 $'
  4.  
  5. # Copyright (c) 2005-2008 Vasco Nunes, Piotr O┼╝arowski
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU Library General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  20.  
  21. # You may use and distribute this software under the terms of the
  22. # GNU General Public License, version 2 or later
  23.  
  24. import sys
  25. import os
  26. import string
  27. import gtk
  28. import gutils
  29. import gobject
  30. import gettext
  31. import platform
  32. import re
  33. import gettext
  34. from locale import getdefaultlocale
  35.  
  36. try:
  37.     import gtkspell
  38.     spell_support = 1
  39. except:
  40.     spell_support = 0
  41.  
  42. def locations(self):
  43.     defaultLang, defaultEnc = getdefaultlocale()
  44.     if defaultEnc is None:
  45.         defaultEnc = 'UTF-8'
  46.     locations = {}
  47.     locations['exec'] = os.path.abspath(os.path.dirname(sys.argv[0])) # deprecated
  48.     locations['lib']  = os.path.dirname(__file__)
  49.     
  50.     if os.name == 'nt' or os.name.startswith('win'): # win32, win64
  51.         import winshell
  52.         from win32com.shell import shellcon, shell
  53.         import shutil
  54.         
  55.         mydocs = winshell.my_documents()
  56.         locations['movie_plugins']  = "%s\\lib\\plugins\\movie" % locations['exec']
  57.         locations['export_plugins'] = "%s\\lib\\plugins\\export" % locations['exec']
  58.         locations['images']         = "%s\\images" % locations['exec']
  59.         locations['share']          = locations['images']
  60.         locations['glade']          = "%s\\glade\\" % locations['exec']
  61.         locations['desktop']        = ''
  62.         locations['i18n']           = "%s\\i18n" % locations['exec']
  63.         os.environ['PATH'] += ";lib;"
  64.         
  65.         # griffith dir location should point to 'Application Data'
  66.         # this is changed on 0.9.5+svn so we need to make it backward compatible
  67.         if os.path.exists(os.path.join(mydocs, 'griffith').decode(defaultEnc)):
  68.             shutil.move(os.path.join(mydocs, 'griffith').decode(defaultEnc),os.path.join(shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0), 'griffith').decode(defaultEnc))
  69.         locations['home']           = os.path.join(shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0), 'griffith').decode(defaultEnc)
  70.         
  71.         # windows hack for locale setting
  72.         lang = os.getenv('LANG')
  73.         if lang is None:
  74.             if defaultLang:
  75.                 lang = defaultLang
  76.         if lang:
  77.             os.environ['LANG'] = lang
  78.  
  79.     elif os.name == 'posix':
  80.         locations['home']  = os.path.join(os.path.expanduser('~'), '.griffith').decode(defaultEnc)
  81.         locations['share'] = os.path.abspath(os.path.join(locations['lib'], '..'))
  82.         locations['glade'] = os.path.join(locations['share'], 'glade')
  83.         locations['i18n']  = os.path.abspath(os.path.join(locations['share'], '..', 'locale'))
  84.         if not os.path.isdir(locations['i18n']):
  85.             locations['i18n'] = os.path.join(locations['share'], 'i18n')
  86.         #some locations
  87.         locations['movie_plugins']  = os.path.join(locations['lib'], 'plugins', 'movie')
  88.         locations['export_plugins'] = os.path.join(locations['lib'], 'plugins', 'export')
  89.         locations['images']  = os.path.join(locations['share'], 'images')
  90.         locations['desktop'] = os.path.join(os.path.expanduser('~'), 'Desktop').decode(defaultEnc)
  91.     else:
  92.         print 'Operating system not supported'
  93.         sys.exit()
  94.     
  95.     from tempfile import gettempdir
  96.     locations['temp'] = gettempdir()
  97.     
  98.     if self._tmp_home is not None: # see gconsole.check_args
  99.         locations['home'] = self._tmp_home.decode(defaultEnc)
  100.         del self._tmp_home
  101.  
  102.     try:
  103.         if not os.path.exists(locations['home']):
  104.             self.debug.show('Creating %s' % locations['home'])
  105.             os.makedirs(locations['home'])
  106.         else:
  107.             self.debug.show("Using Griffith directory: %s" % locations['home'])
  108.     except OSError:
  109.         self.debug.show('Unable to create griffith directory.')
  110.         raise
  111.         sys.exit()
  112.  
  113.     if not os.access(locations['home'], os.W_OK):
  114.         self.debug.show('Cannot write to griffith directory, %s' % locations['home'])
  115.         sys.exit()
  116.  
  117.     # includes plugins in system path for easier importing
  118.     sys.path.append(locations['lib'])
  119.     sys.path.append(locations['movie_plugins'])
  120.     sys.path.append(locations['export_plugins'])
  121.     
  122.     self.locations = locations
  123.     return locations
  124.  
  125. def location_posters(locations, config):
  126.     if config.get('posters', None) is not None:
  127.         locations['posters']  = os.path.join(locations['home'], config.get('posters'))
  128.     elif config.get('type', 'sqlite', section='database') == 'sqlite':
  129.         dbname = config.get('name', 'griffith', section='database')
  130.         if dbname != 'griffith':
  131.             config['posters'] = 'posters_sqlite_' + dbname
  132.         else:
  133.             config['posters'] = 'posters'
  134.         locations['posters'] = os.path.join(locations['home'], config.get('posters'))
  135.         config.save()
  136.     else:
  137.         config['posters'] = "posters_%(type)s_%(host)s_%(port)s_%(name)s_%(user)s" % config.toDict('database')
  138.         locations['posters'] = os.path.join(locations['home'], config.get('posters'))
  139.         config.save()
  140.     # check if posters dir exists
  141.     if not os.path.isdir(locations['posters']):
  142.         os.makedirs(locations['posters'])
  143.  
  144. def gui(self):
  145.     self._ = None
  146.     self.debug.show("running on %s - %s" % (os.name, platform.system()))
  147.     if os.name == 'nt' or os.name.startswith('win'):
  148.         self.windows = True
  149.     else:
  150.         self.windows = False
  151.         
  152.     if platform.system() == 'Darwin':
  153.         self.mac = True
  154.     else:
  155.         self.mac = False
  156.     
  157.     self.griffith_dir = self.locations['home']    # deprecated
  158.     
  159.     if self.windows:
  160.         gtk.rc_parse('%s\\gtkrc' % self.locations['exec'])
  161.  
  162.  
  163.     gf = os.path.join(self.locations['glade'], 'griffith.glade')
  164.     from widgets import define_widgets
  165.     define_widgets(self, gtk.glade.XML(gf))
  166.  
  167.     self.pdf_reader = self.config.get('pdf_reader')
  168.  
  169. def i18n(self, location):
  170.     gettext.bindtextdomain('griffith', location)
  171.     gettext.textdomain('griffith')
  172.     gtk.glade.bindtextdomain('griffith', location)
  173.     gtk.glade.textdomain('griffith')
  174.     gettext.install('griffith', location, unicode=1)
  175.  
  176. def toolbar(self):
  177.     """if toolbar is hide in config lets hide the widget"""
  178.     if not self.config.get('view_toolbar', 'True', section='window'):
  179.         self.widgets['toolbar'].hide()
  180.         self.widgets['menu']['toolbar'].set_active(False)
  181.  
  182. def treeview(self):
  183.     self.treemodel = gtk.TreeStore(str, gtk.gdk.Pixbuf, str, str, str, str, bool, str, str)
  184.     self.widgets['treeview'].set_model(self.treemodel)
  185.     self.widgets['treeview'].set_headers_visible(True)
  186.     # number column
  187.     renderer=gtk.CellRendererText()
  188.     self.number_column=gtk.TreeViewColumn(_('N.'), renderer, text=0)
  189.     self.number_column.set_resizable(True)
  190.     self.number_column.set_sort_column_id(0)
  191.     self.number_column.set_reorderable(True)
  192.     self.widgets['treeview'].append_column(self.number_column)
  193.     # pic column
  194.     renderer=gtk.CellRendererPixbuf()
  195.     self.image_column=gtk.TreeViewColumn(_('Image'), renderer, pixbuf=1)
  196.     self.image_column.set_resizable(False)
  197.     self.image_column.set_reorderable(True)
  198.     self.widgets['treeview'].append_column(self.image_column)
  199.     # original title column
  200.     renderer=gtk.CellRendererText()
  201.     self.otitle_column=gtk.TreeViewColumn(_('Original Title'), renderer, text=2)
  202.     self.otitle_column.set_resizable(True)
  203.     self.otitle_column.set_sort_column_id(2)
  204.     self.otitle_column.set_reorderable(True)
  205.     self.widgets['treeview'].append_column(self.otitle_column)
  206.     # title column
  207.     renderer=gtk.CellRendererText()
  208.     self.title_column=gtk.TreeViewColumn(_('Title'), renderer, text=3)
  209.     self.title_column.set_resizable(True)
  210.     self.title_column.set_sort_column_id(3)
  211.     self.title_column.set_reorderable(True)
  212.     self.widgets['treeview'].append_column(self.title_column)
  213.     # director column
  214.     renderer=gtk.CellRendererText()
  215.     self.director_column=gtk.TreeViewColumn(_('Director'), renderer, text=4)
  216.     self.director_column.set_sort_column_id(4)
  217.     self.director_column.set_resizable(True)
  218.     self.director_column.set_reorderable(True)
  219.     self.widgets['treeview'].append_column(self.director_column)
  220.     # genre column
  221.     renderer=gtk.CellRendererText()
  222.     self.genre_column=gtk.TreeViewColumn(_('Genre'), renderer, text=5)
  223.     self.genre_column.set_sort_column_id(5)
  224.     self.genre_column.set_resizable(True)
  225.     self.genre_column.set_reorderable(True)
  226.     self.widgets['treeview'].append_column(self.genre_column)
  227.     # seen column
  228.     renderer=gtk.CellRendererToggle()
  229.     self.seen_column=gtk.TreeViewColumn(_('Seen it'), renderer, active=6)
  230.     self.seen_column.set_sort_column_id(6)
  231.     self.seen_column.set_resizable(True)
  232.     self.seen_column.set_reorderable(True)
  233.     self.widgets['treeview'].insert_column(self.seen_column, 1)
  234.     # year column
  235.     renderer=gtk.CellRendererText()
  236.     renderer.set_property('xalign', 0.5)
  237.     self.year_column=gtk.TreeViewColumn(_('Year'), renderer, text=7)
  238.     self.year_column.set_sort_column_id(7)
  239.     self.year_column.set_resizable(True)
  240.     self.year_column.set_alignment(0.5)
  241.     self.year_column.set_reorderable(True)
  242.     self.widgets['treeview'].append_column(self.year_column)
  243.     # runtime column
  244.     renderer=gtk.CellRendererText()
  245.     renderer.set_property('xalign', 1)
  246.     self.runtime_column=gtk.TreeViewColumn(_('Runtime'), renderer, text=8)
  247.     self.runtime_column.set_sort_column_id(8)
  248.     self.runtime_column.set_resizable(True)
  249.     self.runtime_column.set_alignment(1)
  250.     self.runtime_column.set_reorderable(True)
  251.     self.widgets['treeview'].append_column(self.runtime_column)
  252.     # rating column
  253.     renderer=gtk.CellRendererText()
  254.     renderer.set_property('xalign', 0.5)
  255.     self.rating_column=gtk.TreeViewColumn(_('Rating'), renderer, text=9)
  256.     self.rating_column.set_sort_column_id(9)
  257.     self.rating_column.set_resizable(True)
  258.     self.rating_column.set_alignment(0.5)
  259.     self.rating_column.set_reorderable(True)
  260.     self.widgets['treeview'].append_column(self.rating_column)
  261.     # reflect saved column order
  262.     columnorder = self.config.get('columnorder', None, section='mainlist')
  263.     if not columnorder is None:
  264.         currentcol = None
  265.         columnordersplitted = re.split('[ \t]*,[ \t]*', columnorder)
  266.         for col in columnordersplitted:
  267.             if col == 'number':
  268.                 self.widgets['treeview'].move_column_after(self.number_column, currentcol)
  269.                 currentcol = self.number_column
  270.             elif col == 'image':
  271.                 self.widgets['treeview'].move_column_after(self.image_column, currentcol)
  272.                 currentcol = self.image_column
  273.             elif col == 'otitle':
  274.                 self.widgets['treeview'].move_column_after(self.otitle_column, currentcol)
  275.                 currentcol = self.otitle_column
  276.             elif col == 'title':
  277.                 self.widgets['treeview'].move_column_after(self.title_column, currentcol)
  278.                 currentcol = self.title_column
  279.             elif col == 'director':
  280.                 self.widgets['treeview'].move_column_after(self.director_column, currentcol)
  281.                 currentcol = self.director_column
  282.             elif col == 'genre':
  283.                 self.widgets['treeview'].move_column_after(self.genre_column, currentcol)
  284.                 currentcol = self.genre_column
  285.             elif col == 'seen':
  286.                 self.widgets['treeview'].move_column_after(self.seen_column, currentcol)
  287.                 currentcol = self.seen_column
  288.             elif col == 'year':
  289.                 self.widgets['treeview'].move_column_after(self.year_column, currentcol)
  290.                 currentcol = self.year_column
  291.             elif col == 'runtime':
  292.                 self.widgets['treeview'].move_column_after(self.runtime_column, currentcol)
  293.                 currentcol = self.runtime_column
  294.             elif col == 'rating':
  295.                 self.widgets['treeview'].move_column_after(self.rating_column, currentcol)
  296.                 currentcol = self.rating_column
  297.     # add data to treeview
  298.     self.total = int(self.db.Movie.count())
  299.     self.widgets['treeview'].show()
  300.  
  301. def loans_treeview(self):
  302.     self.loans_treemodel = gtk.TreeStore(str, str, str) # move to self.widgets
  303.     self.widgets['movie']['loan_history'].set_model(self.loans_treemodel)
  304.     self.widgets['movie']['loan_history'].set_headers_visible(True)
  305.     # loan date
  306.     renderer=gtk.CellRendererText()
  307.     self.date_column=gtk.TreeViewColumn(_('Loan Date'), renderer, text=0)
  308.     self.date_column.set_resizable(True)
  309.     self.widgets['movie']['loan_history'].append_column(self.date_column)
  310.     self.date_column.set_sort_column_id(0)
  311.     # return date
  312.     renderer=gtk.CellRendererText()
  313.     self.return_column=gtk.TreeViewColumn(_('Return Date'), renderer, text=1)
  314.     self.return_column.set_resizable(True)
  315.     self.widgets['movie']['loan_history'].append_column(self.return_column)
  316.     # loan to
  317.     renderer=gtk.CellRendererText()
  318.     self.loaner_column=gtk.TreeViewColumn(_('Loaned To'), renderer, text=2)
  319.     self.loaner_column.set_resizable(True)
  320.     self.widgets['movie']['loan_history'].append_column(self.loaner_column)
  321.  
  322. def lang_treeview(self):
  323.     treeview = self.widgets['add']['lang_treeview']
  324.     self.lang['model'] = gtk.TreeStore(str, str, str, str, str)
  325.     treeview.set_model(self.lang['model'])
  326.     treeview.set_headers_visible(True)
  327.  
  328.     model = self.lang['lang'] = gtk.ListStore(int, str)
  329.     for i in self.db.Lang.select():
  330.         model.append([i.lang_id, i.name])
  331.     combo = gtk.CellRendererCombo()
  332.     combo.set_property('model', model)
  333.     combo.set_property('text-column', 1)
  334.     combo.set_property('editable', True)
  335.     combo.set_property('has-entry', False)
  336.     combo.connect('edited', self.on_tv_lang_combo_edited, 0)
  337.     column=gtk.TreeViewColumn(_('Language'), combo, text=0)
  338.     column.set_property('min-width', 80)
  339.     column.set_property('resizable', True)
  340.     column.set_sort_column_id(0)
  341.     treeview.append_column(column)
  342.     
  343.     model = self.lang['type'] = gtk.ListStore(int, str)
  344.     #i = 0
  345.     #for lang_type in self._lang_types:
  346.     #    model.append([i, lang_type])
  347.     #    i += 1
  348.     model.append([0, ''])
  349.     model.append([1, _('lector')])
  350.     model.append([2, _('dubbing')])
  351.     model.append([3, _('subtitles')])
  352.     model.append([4, _("commentary")])
  353.     combo = gtk.CellRendererCombo()
  354.     combo.set_property('model', model)
  355.     combo.set_property('text-column', 1)
  356.     combo.set_property('editable', True)
  357.     combo.set_property('has-entry', False)
  358.     combo.connect('edited', self.on_tv_lang_combo_edited, 1)
  359.     column=gtk.TreeViewColumn(_('Type'), combo, text=1)
  360.     column.set_property('min-width', 80)
  361.     column.set_property('resizable', True)
  362.     column.set_sort_column_id(1)
  363.     treeview.append_column(column)
  364.  
  365.     model = self.lang['acodec'] = gtk.ListStore(int, str)
  366.     for i in self.db.ACodec.select():
  367.         model.append([i.acodec_id, i.name])
  368.     combo = gtk.CellRendererCombo()
  369.     combo.set_property('model', model)
  370.     combo.set_property('text-column', 1)
  371.     combo.set_property('editable', True)
  372.     combo.set_property('has-entry', False)
  373.     combo.connect('edited', self.on_tv_lang_combo_edited, 2)
  374.     column=gtk.TreeViewColumn(_('Codec'), combo, text=2)
  375.     column.set_property('min-width', 80)
  376.     column.set_property('resizable', True)
  377.     column.set_sort_column_id(2)
  378.     treeview.append_column(column)
  379.     
  380.     model = self.lang['achannel'] = gtk.ListStore(int, str)
  381.     for i in self.db.AChannel.select():
  382.         model.append([i.achannel_id, i.name])
  383.     combo = gtk.CellRendererCombo()
  384.     combo.set_property('model', model)
  385.     combo.set_property('text-column', 1)
  386.     combo.set_property('editable', True)
  387.     combo.set_property('has-entry', False)
  388.     combo.connect('edited', self.on_tv_lang_combo_edited, 3)
  389.     column=gtk.TreeViewColumn(_('Channels'), combo, text=3)
  390.     column.set_property('min-width', 80)
  391.     column.set_property('resizable', True)
  392.     column.set_sort_column_id(3)
  393.     treeview.append_column(column)
  394.     
  395.     model = self.lang['subformat'] = gtk.ListStore(int, str)
  396.     for i in self.db.SubFormat.select():
  397.         model.append([i.subformat_id, i.name])
  398.     combo = gtk.CellRendererCombo()
  399.     combo.set_property('model', model)
  400.     combo.set_property('text-column', 1)
  401.     combo.set_property('editable', True)
  402.     combo.set_property('has-entry', False)
  403.     combo.connect('edited', self.on_tv_lang_combo_edited, 4)
  404.     column=gtk.TreeViewColumn(_('Subtitle format'), combo, text=4)
  405.     column.set_property('min-width', 80)
  406.     column.set_property('resizable', True)
  407.     column.set_sort_column_id(4)
  408.     treeview.append_column(column)
  409.     
  410.     treeview.show_all()
  411.  
  412. def movie_plugins(self):
  413.     """
  414.     dinamically finds the movie source information plugins
  415.     and fills the plugins drop down list
  416.     """
  417.     self.plugins = gutils.read_plugins('PluginMovie', \
  418.         self.locations['movie_plugins'])
  419.     self.plugins.sort()
  420.     self.d_plugin = 0
  421.     mcounter = 0
  422.     default_plugin = self.config.get('default_movie_plugin')
  423.     for p in self.plugins:
  424.         plugin_module = os.path.basename(p).replace('.py','')
  425.         plugin_name = plugin_module.replace('PluginMovie','')
  426.         self.widgets['add']['source'].append_text(plugin_name)
  427.         self.widgets['preferences']['default_plugin'].append_text(plugin_name)
  428.         if plugin_name == default_plugin:
  429.             self.widgets['preferences']['default_plugin'].set_active(mcounter)
  430.             self.d_plugin = mcounter
  431.         mcounter = mcounter + 1
  432.     self.widgets['add']['source'].set_active(self.d_plugin)
  433.  
  434. def export_plugins(self):
  435.     """
  436.     dinamically finds the available export plugins
  437.     and fills the export menu entry
  438.     """
  439.     plugins = gutils.read_plugins('PluginExport', \
  440.         self.locations['export_plugins'])
  441.     plugins.sort()
  442.     for p in plugins:
  443.         plugin_module = os.path.basename(p).replace('.py', '')
  444.         plugin_name = plugin_module.replace('PluginExport', '')
  445.         menu_items = gtk.MenuItem(plugin_name)
  446.         self.widgets['menu']['export'].append(menu_items)
  447.         menu_items.connect('activate', self.on_export_activate, plugin_name)
  448.         menu_items.show()
  449.         
  450. def import_plugins(self):
  451.     """
  452.     dinamically finds the available import plugins
  453.     and fills the import menu entry
  454.     """
  455.     
  456.     import plugins.imp, math
  457.  
  458.     fields_to_import = ( 'number','title', 'o_title', 'director', 'year', 'runtime', 'country',
  459.         'seen', 'rating', 'genre', 'studio', 'plot', 'cast', 'notes', 'classification',
  460.         'site', 'o_site', 'trailer', 'medium_id', 'media_num', 'vcodec_id', 'color', 'cond',
  461.         'layers', 'region', 'collection_id', 'volume_id', 'image')
  462.  
  463.     # glade
  464.     glade_file = gtk.glade.XML(os.path.join(self.locations['glade'], 'import.glade'))
  465.     get = lambda x: glade_file.get_widget(x)
  466.     
  467.     w = self.widgets['import'] = {
  468.         'window'    : get('dialog_import'),
  469.         'pwindow'    : get('dialog_progress'),
  470.         'pabort'    : get('p_abortbutton'),
  471.         'fcw'        : get('fcw'),
  472.         'plugin'    : get('combo_plugin'),
  473.         'author'    : get('l_author'),
  474.         'email'        : get('l_email'),
  475.         'version'    : get('l_version'),
  476.         'description'    : get('l_description'),
  477.         'box_import_1'    : get('box_import_1'),
  478.         'box_import_2'    : get('box_import_2'),
  479.         'box_import_3'    : get('box_import_3'),
  480.         'progress'    : get('l_progress'),
  481.         'progressbar'    : get('progressbar'),
  482.         'fields'    : {},
  483.     }
  484.     get('cancel_button').connect('clicked', plugins.imp.on_abort_button_clicked, self)
  485.     get('import_button').connect('clicked', plugins.imp.on_import_button_clicked, self)
  486.     w['plugin'].connect('changed', plugins.imp.on_import_plugin_changed, w)
  487.     w['window'].set_transient_for(self.widgets['window'])
  488.     w['pwindow'].set_transient_for(self.widgets['window'])
  489.     
  490.     for name in plugins.imp.__all__:
  491.         w['plugin'].append_text(name)
  492.     w['plugin'].set_active(0)
  493.     
  494.     # fields to import
  495.     j = 0
  496.     k = math.ceil( len(self.field_names) / float(3) )
  497.     for i in fields_to_import:
  498.         j = j + 1
  499.         w['fields'][i] = gtk.CheckButton(self.field_names[i])
  500.         w['fields'][i].set_active(True) # TODO: get from config
  501.         if j <= k:
  502.             w['box_import_1'].add(w['fields'][i])
  503.         elif j<= 2*k:
  504.             w['box_import_2'].add(w['fields'][i])
  505.         else:
  506.             w['box_import_3'].add(w['fields'][i])
  507.     w['box_import_1'].show_all()
  508.     w['box_import_2'].show_all()
  509.     w['box_import_3'].show_all()
  510.  
  511. def people_treeview(self, create=True):
  512.     row = None
  513.     self.p_treemodel = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
  514.     self.widgets['preferences']['treeview'].set_model(self.p_treemodel)
  515.     self.widgets['preferences']['treeview'].set_headers_visible(True)
  516.  
  517.     if create==True:
  518.         # name column
  519.         renderer=gtk.CellRendererText()
  520.         column=gtk.TreeViewColumn(_('Name'), renderer, text=0)
  521.         column.set_resizable(True)
  522.         column.set_sort_column_id(0)
  523.         self.widgets['preferences']['treeview'].append_column(column)
  524.         # email column
  525.         renderer=gtk.CellRendererText()
  526.         column=gtk.TreeViewColumn(_('E-mail'),renderer, text=1)
  527.         column.set_resizable(True)
  528.         column.set_sort_column_id(1)
  529.         self.widgets['preferences']['treeview'].append_column(column)
  530.     # add data to treeview
  531.     self.p_treemodel.clear()
  532.     for person in self.db.Person.select(order_by='name ASC'):
  533.         myiter = self.p_treemodel.insert_before(None, None)
  534.         self.p_treemodel.set_value(myiter, 0, str(person.name))
  535.         self.p_treemodel.set_value(myiter, 1, str(person.email))
  536.     self.widgets['preferences']['treeview'].show()
  537.  
  538. def combos(self):
  539.     i = 0
  540.     for cond in self._conditions:
  541.         self.widgets['preferences']['condition'].insert_text(i, cond)
  542.         self.widgets['add']['condition'].insert_text(i, cond)
  543.         i += 1
  544.     i = 0
  545.     for color in self._colors:
  546.         self.widgets['preferences']['color'].insert_text(i, color)
  547.         self.widgets['add']['color'].insert_text(i, color)
  548.         i += 1
  549.     i = 0
  550.     for region in self._regions:
  551.         self.widgets['preferences']['region'].insert_text(i, region)
  552.         self.widgets['add']['region'].insert_text(i, region)
  553.         i += 1
  554.     i = 0
  555.     for layer in self._layers:
  556.         self.widgets['preferences']['layers'].insert_text(i, layer)
  557.         self.widgets['add']['layers'].insert_text(i, layer)
  558.         i += 1
  559.     i = 0
  560.     pos_to_activate = 0
  561.     selected_criteria = self.config.get('criteria', None, section='mainlist')
  562.     for criteria in self.search_criteria:
  563.         new_criteria = self.field_names[criteria]
  564.         self.widgets['filter']['criteria'].insert_text(i, new_criteria)
  565.         if selected_criteria == new_criteria:
  566.             pos_to_activate = i
  567.         i += 1
  568.     self.widgets['filter']['criteria'].set_active(pos_to_activate)
  569.     i = 0
  570.     for field in self.sort_criteria:
  571.         if field != 'movie_id':
  572.             self.widgets['preferences']['sortby'].insert_text(i, self.field_names[field])
  573.         else:
  574.             self.widgets['preferences']['sortby'].insert_text(i, _('Last added'))
  575.         i += 1
  576.     self.widgets['preferences']['sortby'].set_wrap_width(3)
  577.     self.widgets['preferences']['sortby'].set_active(0) # Number
  578.  
  579. def dictionaries(self):
  580.     """initializes data filled dynamically by users"""
  581.     import update
  582.     self.am_tags = {} # dictionary for tag CheckBoxes
  583.     update.update_volume_combo_ids(self)
  584.     update.update_collection_combo_ids(self)
  585.     update.update_loanedto_combo_ids(self)
  586.     update.update_bytag_combo_ids(self)
  587.     fill_volumes_combo(self)
  588.     fill_collections_combo(self)
  589.     fill_loanedto_combo(self)
  590.     fill_bytag_combo(self)
  591.     fill_preferences_tags_combo(self)
  592.     language_combos(self)
  593.     acodec_combos(self)
  594.     achannel_combos(self)
  595.     subformat_combos(self)
  596.     vcodec_combos(self)
  597.     media_combos(self)
  598.     create_tag_vbox(self, widget=self.widgets['add']['tag_vbox'], tab=self.am_tags)
  599.     self.sort_criteria = [ # "[]" because of index() 
  600.         'number', 'o_title', 'title', 'director', 'year', 'runtime', 'country',
  601.         'genre', 'studio', 'media_num', 'rating', 'classification', 'collection_id',
  602.         'volume_id', 'cond', 'layers', 'region', 'movie_id']
  603.     self.search_criteria = (
  604.         'o_title', 'title', 'number', 'director', 'plot', 'cast', 'notes', 'year',
  605.         'runtime', 'country', 'genre', 'studio', 'media_num', 'rating')
  606.     self.field_names = {
  607.         'cast'           : _('Cast'),
  608.         'classification' : _('Classification'),
  609.         'collection_id'  : _('Collection'),
  610.         'color'          : _('Color'),
  611.         'cond'           : _('Condition'),
  612.         'country'        : _('Country'),
  613.         'director'       : _('Director'),
  614.         'genre'          : _('Genre'),
  615.         'image'          : _('Image'),
  616.         'layers'         : _('Layers'),
  617.         'loaned'         : _('Loaned'),
  618.         'media_num'      : _('Discs'),
  619.         'medium_id'      : _('Medium'),
  620.         'notes'          : _('Notes'),
  621.         'number'         : _('Number'),
  622.         'o_site'         : _('Official site'),
  623.         'o_title'        : _('Original Title'),
  624.         'plot'           : _('Plot'),
  625.         'rating'         : _('Rating'),
  626.         'region'         : _('Region'),
  627.         'runtime'        : _('Runtime'),
  628.         'seen'           : _('Seen it'),
  629.         'site'           : _('Site'),
  630.         'studio'         : _('Studio'),
  631.         'title'          : _('Title'),
  632.         'trailer'        : _('Trailer'),
  633.         'vcodec_id'      : _('Video codec'),
  634.         'volume_id'      : _('Volume'),
  635.         'year'           : _('Year')}
  636.     self._conditions = (_('N/A'), _('Damaged'), _('Poor'),  _('Fair'), _('Good'), _('Excellent'))
  637.     self._colors = (_('N/A'), _('Color'), _('Black and White'), _('Mixed'))
  638.     self._lang_types = ('', _('lector'), _('dubbing'), _('subtitles'), _('commentary'))
  639.     self._layers = (_('N/A'), _('Single Side, Single Layer'), _('Single Side, Dual Layer'), _('Dual Side, Single Layer'), _('Dual Side, Dual Layer'))
  640.     self._regions = (
  641.         _('Region 0 (No Region Coding)'),
  642.         _('Region 1 (United States of America, Canada)'),
  643.         _('Region 2 (Europe,including France, Greece, Turkey, Egypt, Arabia, Japan and South Africa)'),
  644.         _('Region 3 (Korea, Thailand, Vietnam, Borneo and Indonesia)'),
  645.         _('Region 4 (Australia and New Zealand, Mexico, the Caribbean, and South America)'),
  646.         _('Region 5 (India, Africa, Russia and former USSR countries)'),
  647.         _('Region 6 (Popular Republic of China)'),
  648.         _('Region 7 (Reserved for Unspecified Special Use)'),
  649.         _('Region 8 (Airlines/Cruise Ships)'),
  650.     )
  651.  
  652. def web_results(self):
  653.     self.treemodel_results = gtk.TreeStore(str, str)
  654.     self.widgets['results']['treeview'].set_model(self.treemodel_results)
  655.     self.widgets['results']['treeview'].set_headers_visible(False)
  656.     # column ids
  657.     renderer=gtk.CellRendererText()
  658.     self.column1=gtk.TreeViewColumn(None, renderer, text=0)
  659.     self.column1.set_visible(False)
  660.     self.widgets['results']['treeview'].append_column(self.column1)
  661.     # column titles
  662.     renderer=gtk.CellRendererText()
  663.     self.column2=gtk.TreeViewColumn(None, renderer, text=1)
  664.     self.column2.set_resizable(True)
  665.     self.column2.set_sort_column_id(1)
  666.     self.widgets['results']['treeview'].append_column(self.column2)
  667.  
  668. def gtkspell(self):
  669.     global spell_support
  670.     spell_error = False
  671.     if self.posix and spell_support:
  672.         if self.config.get('gtkspell', False, section='spell') == True:
  673.             if self.config.get('notes', True, section='spell') == True and self.config.get('lang', section='spell') != '':
  674.                 try:
  675.                     self.notes_spell = gtkspell.Spell(self.widgets['add']['cast'], self.config.get('lang', section='spell'))
  676.                 except:
  677.                     spell_error = True
  678.             if self.config.get('plot', True, section='spell')==True and self.config.get('lang', section='spell') != '':
  679.                 try:
  680.                     self.plot_spell = gtkspell.Spell(self.widgets['add']['plot'], self.config.get('lang', section='spell'))
  681.                 except:
  682.                     spell_error = True
  683.             if spell_error:
  684.                 self.debug.show('Dictionary not available. Spellcheck will be disabled.')
  685.                 if not self.config.get('notified', False, section='spell'):
  686.                     gutils.info(self, _("Dictionary not available. Spellcheck will be disabled. \n" + \
  687.                         "Please install the aspell-%s package or adjust the spellchekcer preferences.")%self.config.get('lang', section='spell'), \
  688.                         self.widgets['preferences']['window'])
  689.                     self.config.set('notified', True, section='spell')
  690.                     self.config.save()
  691.     else:
  692.         self.debug.show('Spellchecker is not available')
  693.  
  694. def preferences(self):
  695.     self.widgets['preferences']['db_type'].insert_text(0,'SQLite3 (internal)')
  696.     self.widgets['preferences']['db_type'].insert_text(1,'PostgreSQL')
  697.     self.widgets['preferences']['db_type'].insert_text(2,'MySQL')
  698.     self.widgets['preferences']['db_type'].insert_text(3,'Microsoft SQL')
  699.     self.widgets['preferences']['db_host'].set_text(self.config.get('host', '', section='database'))
  700.     self.widgets['preferences']['db_port'].set_value(int(self.config.get('port', 0, section='database')))
  701.     self.widgets['preferences']['db_user'].set_text(self.config.get('user', '', section='database'))
  702.     self.widgets['preferences']['db_passwd'].set_text(self.config.get('passwd', '', section='database'))
  703.     self.widgets['preferences']['db_name'].set_text(self.config.get('name', '', section='database'))
  704.     db_type = self.config.get('type', 'sqlite', section='database')
  705.     if db_type == 'postgres':
  706.         self.widgets['preferences']['db_type'].set_active(1)
  707.     elif db_type == 'mysql':
  708.         self.widgets['preferences']['db_type'].set_active(2)
  709.     elif db_type == 'mssql':
  710.         self.widgets['preferences']['db_type'].set_active(3)
  711.     else:
  712.         self.widgets['preferences']['db_type'].set_active(0)
  713.  
  714. def fill_volumes_combo(self, default=0):
  715.     _tmp = self.initialized
  716.     self.initialized = False # don't refresh main treeview
  717.     self.widgets['add']['volume'].get_model().clear()
  718.     self.widgets['filter']['volume'].get_model().clear()
  719.     for i in self.volume_combo_ids:
  720.         vol_id = self.volume_combo_ids[i]
  721.         if vol_id>0:
  722.             name = self.db.Volume.get_by(volume_id=vol_id).name
  723.         else:
  724.             name = ''
  725.         self.widgets['add']['volume'].insert_text(int(i), str(name))
  726.         # add some white spaces to prevent scrollbar hides parts of the names    
  727.         self.widgets['filter']['volume'].insert_text(int(i), str(name) + '   ')
  728.     self.initialized = _tmp
  729.     self.widgets['add']['volume'].show_all()
  730.     self.widgets['filter']['volume'].show_all()
  731.     self.widgets['filter']['volume'].set_active(0)
  732.     i = gutils.findKey(default, self.volume_combo_ids)
  733.     if i is not None:
  734.         self.widgets['add']['volume'].set_active(int(i))
  735.     self.widgets['add']['volume'].set_wrap_width(3)
  736.  
  737. def fill_collections_combo(self, default=0):
  738.     _tmp = self.initialized
  739.     self.initialized = False # don't refresh main treeview
  740.     self.widgets['add']['collection'].get_model().clear()
  741.     self.widgets['filter']['collection'].get_model().clear()
  742.     for i in self.collection_combo_ids:
  743.         col_id = self.collection_combo_ids[i]
  744.         if col_id>0:
  745.             name = self.db.Collection.get_by(collection_id=col_id).name
  746.         else:
  747.             name = ''
  748.         self.widgets['add']['collection'].insert_text(int(i), str(name))
  749.         # add some white spaces to prevent scrollbar hides parts of the names    
  750.         self.widgets['filter']['collection'].insert_text(int(i), str(name) + '   ')
  751.     self.initialized = _tmp
  752.     self.initialized = False
  753.     self.widgets['add']['collection'].show_all()
  754.     self.widgets['filter']['collection'].show_all()
  755.     self.widgets['filter']['collection'].set_active(0)
  756.     i = gutils.findKey(default, self.collection_combo_ids)
  757.     if i is not None:
  758.         self.widgets['add']['collection'].set_active(int(i))
  759.     self.widgets['add']['collection'].set_wrap_width(2)
  760.  
  761. def fill_loanedto_combo(self):
  762.     _tmp = self.initialized
  763.     self.initialized = False # don't refresh main treeview
  764.     self.widgets['filter']['loanedto'].get_model().clear()
  765.     for i in self.loanedto_combo_ids:
  766.         per_id = self.loanedto_combo_ids[i]
  767.         if per_id>0:
  768.             name = self.db.Person.get_by(person_id=per_id).name
  769.         else:
  770.             name = ''
  771.         # add some white spaces to prevent scrollbar hides parts of the names    
  772.         self.widgets['filter']['loanedto'].insert_text(int(i), str(name) + '   ')
  773.     self.initialized = _tmp
  774.     self.widgets['filter']['loanedto'].show_all()
  775.     self.widgets['filter']['loanedto'].set_active(0)
  776.  
  777. def fill_bytag_combo(self):
  778.     _tmp = self.initialized
  779.     self.initialized = False # don't refresh main treeview
  780.     self.widgets['filter']['tag'].get_model().clear()
  781.     for i in self.bytag_combo_ids:
  782.         id = self.bytag_combo_ids[i]
  783.         if id>0:
  784.             name = self.db.Tag.get_by(tag_id=id).name
  785.         else:
  786.             name = ''
  787.         # add some white spaces to prevent scrollbar hides parts of the names    
  788.         self.widgets['filter']['tag'].insert_text(int(i), str(name) + '   ')
  789.     self.initialized = _tmp
  790.     self.widgets['filter']['tag'].show_all()
  791.     self.widgets['filter']['tag'].set_active(0)
  792.  
  793. def fill_preferences_tags_combo(self):
  794.     _tmp = self.initialized
  795.     self.initialized = False # don't refresh main treeview
  796.     self.widgets['preferences']['tag_name'].get_model().clear()
  797.     self.tags_ids = {}
  798.     i = 0
  799.     for tag in self.db.Tag.select():
  800.         self.tags_ids[i] = tag.tag_id
  801.         self.widgets['preferences']['tag_name'].insert_text(int(i), str(tag.name))
  802.         i += 1
  803.     self.initialized = _tmp
  804.     self.widgets['preferences']['tag_name'].show_all()
  805.  
  806. def language_combos(self):
  807.     self.widgets['preferences']['lang_name'].get_model().clear()
  808.     self.languages_ids = {}
  809.     self.languages_ids[0] = 0    # empty one
  810.     self.widgets['preferences']['lang_name'].insert_text(0, '')
  811.     i = 1
  812.     for lang in self.db.Lang.select():
  813.         self.languages_ids[i] = lang.lang_id
  814.         self.widgets['preferences']['lang_name'].insert_text(int(i), str(lang.name))
  815.         i += 1
  816.     self.widgets['preferences']['lang_name'].show_all()
  817.     # add movie languages treeview
  818.     self.lang['lang'].clear()
  819.     for i in self.db.Lang.select():
  820.         self.lang['lang'].append([i.lang_id, i.name])
  821. def acodec_combos(self):
  822.     self.widgets['preferences']['acodec_name'].get_model().clear()
  823.     self.acodecs_ids = {}
  824.     self.acodecs_ids[0] = 0    # empty one
  825.     self.widgets['preferences']['acodec_name'].insert_text(0, '')
  826.     i = 1
  827.     for acodec in self.db.ACodec.select():
  828.         self.acodecs_ids[i] = acodec.acodec_id
  829.         self.widgets['preferences']['acodec_name'].insert_text(int(i), str(acodec.name))
  830.         i += 1
  831.     self.widgets['preferences']['acodec_name'].show_all()
  832.     # add movie languages treeview
  833.     self.lang['acodec'].clear()
  834.     for i in self.db.ACodec.select():
  835.         self.lang['acodec'].append([i.acodec_id, i.name])
  836. def achannel_combos(self):
  837.     self.widgets['preferences']['achannel_name'].get_model().clear()
  838.     self.achannels_ids = {}
  839.     self.achannels_ids[0] = 0    # empty one
  840.     self.widgets['preferences']['achannel_name'].insert_text(0, '')
  841.     i = 1
  842.     for achannel in self.db.AChannel.select():
  843.         self.achannels_ids[i] = achannel.achannel_id
  844.         self.widgets['preferences']['achannel_name'].insert_text(int(i), str(achannel.name))
  845.         i += 1
  846.     self.widgets['preferences']['achannel_name'].show_all()
  847.     # add movie languages treeview
  848.     self.lang['achannel'].clear()
  849.     for i in self.db.AChannel.select():
  850.         self.lang['achannel'].append([i.achannel_id, i.name])
  851. def subformat_combos(self):
  852.     self.widgets['preferences']['subformat_name'].get_model().clear()
  853.     self.subformats_ids = {}
  854.     self.subformats_ids[0] = 0    # empty one
  855.     self.widgets['preferences']['subformat_name'].insert_text(0, '')
  856.     i = 1
  857.     for subformat in self.db.SubFormat.select():
  858.         self.subformats_ids[i] = subformat.subformat_id
  859.         self.widgets['preferences']['subformat_name'].insert_text(int(i), str(subformat.name))
  860.         i += 1
  861.     self.widgets['preferences']['subformat_name'].show_all()
  862.     # add movie languages treeview
  863.     self.lang['subformat'].clear()
  864.     for i in self.db.SubFormat.select():
  865.         self.lang['subformat'].append([i.subformat_id, i.name])
  866.  
  867. def media_combos(self):
  868.     # clear data
  869.     self.widgets['preferences']['medium_name'].get_model().clear()
  870.     self.widgets['preferences']['media'].get_model().clear()
  871.     self.widgets['add']['media'].get_model().clear()
  872.     
  873.     self.media_ids = {}
  874.  
  875.     self.media_ids[0] = None
  876.     self.widgets['preferences']['medium_name'].insert_text(0, '')
  877.     self.widgets['add']['media'].insert_text(0, _('N/A'))
  878.     self.widgets['preferences']['media'].insert_text(0, _('N/A'))
  879.     i = 1
  880.     for medium in self.db.Medium.select():
  881.         self.media_ids[i] = medium.medium_id
  882.         self.widgets['preferences']['medium_name'].insert_text(int(i), str(medium.name))
  883.         self.widgets['add']['media'].insert_text(int(i), str(medium.name))
  884.         self.widgets['preferences']['media'].insert_text(int(i), str(medium.name))
  885.         i += 1
  886.  
  887.     self.widgets['preferences']['medium_name'].show_all()
  888.     self.widgets['add']['media'].show_all()
  889.     self.widgets['preferences']['media'].show_all()
  890.     if self.config.has_key('media', section='defaults'):
  891.         pos = gutils.findKey(self.config.get('media', section='defaults'), self.media_ids)
  892.         if pos  is not None:
  893.             self.widgets['preferences']['media'].set_active(int(pos))
  894.         else:
  895.             self.widgets['preferences']['media'].set_active(0)
  896.     else:
  897.         self.widgets['preferences']['media'].set_active(0)
  898.  
  899. def vcodec_combos(self):
  900.     # clear data
  901.     self.widgets['preferences']['vcodec_name'].get_model().clear()
  902.     self.widgets['preferences']['vcodec'].get_model().clear()
  903.     self.widgets['add']['vcodec'].get_model().clear()
  904.     
  905.     self.vcodecs_ids = {}
  906.     
  907.     self.vcodecs_ids[0] = None
  908.     self.widgets['preferences']['vcodec_name'].insert_text(0, '')
  909.     self.widgets['add']['vcodec'].insert_text(0, _('N/A'))
  910.     self.widgets['preferences']['vcodec'].insert_text(0, _('N/A'))
  911.     i = 1
  912.     for vcodec in self.db.VCodec.select():
  913.         self.vcodecs_ids[i] = vcodec.vcodec_id
  914.         self.widgets['preferences']['vcodec_name'].insert_text(int(i), str(vcodec.name))
  915.         self.widgets['add']['vcodec'].insert_text(int(i), str(vcodec.name))
  916.         self.widgets['preferences']['vcodec'].insert_text(int(i), str(vcodec.name))
  917.         i += 1
  918.  
  919.     self.widgets['preferences']['vcodec_name'].show_all()
  920.     self.widgets['add']['vcodec'].show_all()
  921.     self.widgets['preferences']['vcodec'].show_all()
  922.     
  923.     pos = gutils.findKey(self.config.get('vcodec', 0, section='defaults'), self.vcodecs_ids)
  924.     if pos is not None:
  925.         self.widgets['preferences']['vcodec'].set_active(int(pos))
  926.     else:
  927.         self.widgets['preferences']['vcodec'].set_active(0)
  928.  
  929. def create_tag_vbox(self, widget, tab):
  930.     for i in widget.get_children():
  931.         i.destroy()
  932.     for i in self.tags_ids:
  933.         tag_id = self.tags_ids[i]
  934.         tag_name = self.db.Tag.get_by(tag_id=tag_id).name
  935.         tab[i] = gtk.CheckButton(str(tag_name))
  936.         tab[i].set_active(False)
  937.         widget.pack_start(tab[i])
  938.     widget.show_all()
  939.  
  940. def remove_hbox(self, widget, tab):
  941.     number = len(widget.get_children())-1    # last box number
  942.     try:
  943.         tab.pop()
  944.         widget.remove(widget.get_children().pop())
  945.     except:
  946.         self.debug.show('List is empty')
  947.     widget.show_all()
  948.  
  949.